package cn.rsa.aiwangren.config;

import cn.rsa.aiwangren.advice.DecryptRequestBodyAdvice;
import cn.rsa.aiwangren.advice.EncryptResponseBodyAdvice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class AutoConfiguration {
    private final Logger logger = LoggerFactory.getLogger(AutoConfiguration.class);

    @Bean
    public SecretKeyConfig secretKeyConfig() {
        return new SecretKeyConfig();
    }

    @Bean
    public DecryptRequestBodyAdvice decryptRequestBodyAdvice() {
        return new DecryptRequestBodyAdvice();
    }

    @Bean
    public EncryptResponseBodyAdvice encryptResponseBodyAdvice() {
        return new EncryptResponseBodyAdvice();
    }

    @PostConstruct
    public void initiate() {
        String colorReset = "\u001B[0m";
        String colorGreen = "\u001B[31m";
        logger.info("\n" +
                "    .______          _______.     ___      \n" +
                "     |   _  \\        /       |    /   \\     \n" +
                "     |  |_)  |      |   (----`   /  ^  \\    \n" +
                "     |      /        \\   \\      /  /_\\  \\   \n" +
                "     |  |\\  \\----.----)   |    /  _____  \\  \n" +
                "     | _| `._____|_______/    /__/     \\__\\               \n" +
                colorGreen + " :: Spring Boot RSA ::                (v1.5.1)" + colorReset);
    }
}
